var AjaxCrud = QualityCheck.AjaxCRUD;
var serverUrl = QualityCheck.GPUD.ServiceConfig;
//部门科室二级联动菜单
function departmentMenu(){
	var userKey = $("#user-name",parent.parent.parent.document).attr("key");
	var schoolcode = $("#user-name",parent.parent.parent.document).attr("schoolcode");
	var data = {
			cmd:"getAllDepartments",
			model:"department",
			userKey:userKey,
			data:{
				schoolcode:schoolcode
			},
			remark:"",						
	};
	AjaxCrud.get(serverUrl.ServerLoginUrl,data,function(res){
		if(res.result == 1 && res.data != undefined && res.data != ""){
			var data = res.data;
			var contents = "<a departmentcodes = '' office=''  href=\"javascript:void(0)\" class=\"teachers-a1-select\" title=''>所有</a><br>";
			for(var i = 0; i < data.length; i++){
				contents += "<a departmentcodes='"+data[i].departmentcode+"' office='"+data[i].office+"' href=\"javascript:void(0)\" title='"+data[i].department+"' >"+data[i].department+"</a><br>";
			}
			$("#teacher-regon-content",parent.parent.parent.document).empty();
			$("#teacher-regon-content",parent.parent.parent.document).append(contents);
			var cont = "<a href=\"javascript:void(0)\" class=\"teachers-a2-select\" title=''>所有</a><br>";
			var offices = $("#teacher-regon-content a",parent.parent.parent.document);
			for(var i = 0; i < offices.length; i++){
				if( i == 0){
					cont  += "";
				}else{
					var officesNameArr = offices[i].getAttribute("office").split(",");
					for(var j = 0; j < officesNameArr.length; j++){
						cont  += "<a  href=\"javascript:void(0)\" title='"+officesNameArr[j]+"'>"+officesNameArr[j]+"</a><br>";
					}
				}
			}
			$("#teachers-content",parent.parent.parent.document).empty();
			$("#teachers-content",parent.parent.parent.document).append(cont);
			$("#teachers-content a",parent.parent.parent.document).unbind("click");
			$("#teachers-content a",parent.parent.parent.document).click(function(){
				$("#teachers-content a",parent.parent.parent.document).removeClass("teachers-a2-select");
				$(this,parent.parent.parent.document).addClass("teachers-a2-select");
				initTeacherTable(1,10000);
			});
			$("#teacher-regon-content a",parent.parent.parent.document).unbind("click");
			$("#teacher-regon-content a",parent.parent.parent.document).click(function(){
				var classes = $(this).attr("office");
				var classcodes = $(this).attr("departmentcodes");
				var classArr = classes.split(",");
				var classcodeArr = classcodes.split(",");
				if(classes != ""){
					var cont = "<a href=\"javascript:void(0)\" class=\"teachers-a2-select\" title=''>所有</a><br>";
					for(var i = 0; i < classArr.length; i++){
						cont += "<a classcode='"+classcodeArr[i]+"' href=\"javascript:void(0)\" title='"+classArr[i]+"'>"+classArr[i]+"</a><br>";
					}
					$("#teachers-content",parent.parent.parent.document).empty();
					$("#teachers-content",parent.parent.parent.document).append(cont);
					$("#teacher-regon-content a",parent.parent.parent.document).removeClass("teachers-a1-select");
					$(this,parent.parent.parent.document).addClass("teachers-a1-select");
					initTeacherTable(1,10000);
					
				}else{
					var cont = "<a href=\"javascript:void(0)\" class=\"teachers-a2-select\" title=''>所有</a><br>";
					var offices = $("#teacher-regon-content a",parent.parent.parent.document);
					for(var i = 0; i < offices.length; i++){
						if( i == 0){
							cont  += "";
						}else{
							var officesNameArr = offices[i].getAttribute("office").split(",");
							for(var j = 0; j < officesNameArr.length; j++){
								cont  += "<a  href=\"javascript:void(0)\" title='"+officesNameArr[j]+"'>"+officesNameArr[j]+"</a><br>";
							}
						}
					}
					$("#teachers-content",parent.parent.parent.document).empty();
					$("#teachers-content",parent.parent.parent.document).append(cont);
					$("#teacher-regon-content a",parent.parent.parent.document).removeClass("teachers-a1-select");
					$(this,parent.parent.parent.document).addClass("teachers-a1-select");
					initTeacherTable(1,10000);
				}
				$("#teachers-content a",parent.parent.parent.document).unbind("click");
				$("#teachers-content a",parent.parent.parent.document).click(function(){
					$("#teachers-content a",parent.parent.parent.document).removeClass("teachers-a2-select");
					$(this,parent.parent.parent.document).addClass("teachers-a2-select");
					initTeacherTable(1,10000);
				});
			});
			
		}else{
			
		}
	},null,null);
} 
function initTeacherTable(currentpage,pagesize){
	var userKey = $("#user-name",parent.parent.parent.document).attr("key");
	var schoolcode = $("#user-name",parent.parent.parent.document).attr("schoolcode");
	var department1 = $(".teachers-a1-select",parent.parent.parent.document).attr("title");
	var department2 = $(".teachers-a2-select",parent.parent.parent.document).attr("title");
	var name = "";
	var data = {
			cmd:"getAllTeachers",
			model:"teacher",
			userKey:userKey,
			data:{
				currentpage:currentpage,
				pagesize:pagesize,
				department1:encodeURI(department1),
				department2:encodeURI(department2),
				name:encodeURI(name),
				schoolcode:schoolcode
			},
			remark:"",
	};
	AjaxCrud.get(serverUrl.ServerLoginUrl,data,function(res){
		if(res.result == 1 && res.data != undefined && res.data != ""){
			var contents = "";
			var list = res.data.data;
			for(var i = 0; i < list.length; i ++){
				contents += "<a href='javascript:void(0)' teachercode='" + list[i].teachercode +"' title='" + list[i].name + "'>" + list[i].name + "</a><br>";
			}
			$("#teacher-department-content",parent.parent.parent.document).empty();
			$("#teacher-department-content",parent.parent.parent.document).append(contents);
		}else{
			var contents = "未查询到教师！";
			$("#teacher-department-content",parent.parent.parent.document).empty();
			$("#teacher-department-content",parent.parent.parent.document).append(contents);
		}
		$("#teacher-department-content a",parent.parent.parent.document).unbind("click");
		$("#teacher-department-content a",parent.parent.parent.document).click(function(){
			$("#teacher-department-content a",parent.parent.parent.document).removeClass("teacher-a3-select");
			$(this,parent.parent.parent.document).addClass("teacher-a3-select");
			var teachercode = $(this).attr("teachercode");
			var name = $(this).attr("title");
			$("#teacher-choice-name",parent.parent.parent.document).val(name);
			$("#teacher-code",parent.parent.parent.document).val(teachercode);
		});
	},null,null);											
}